﻿@{
    WebSecurity.RequireAuthenticatedUser();
    Layout = "~/_SiteLayout.cshtml";
    Page.CustStatus = RefDataManager.GetCustStatLkUpVal();
    Page.CustClass = RefDataManager.GetCustClassLkUpVal();
    Page.Region = RefDataManager.GetRegionLkUpVal();
    Page.CustGender = RefDataManager.GetGenderLkUpVal();
    Page.Nationality = RefDataManager.GetNatLkUpVal();
    Page.CustIdType = RefDataManager.GetIDTypeLkUpVal();
    Page.SrcOfFund = RefDataManager.GetSrcOfFundsLkUpVal();
    Page.EmpType = RefDataManager.GetEmpTypeLkUpVal();
    Page.CCStatus = RefDataManager.GetCashCardStatLkUpVal();
    Page.CCDocStatus = RefDataManager.GetDocStatLkUpVal();
    Page.CCType = RefDataManager.GetCashCardTypeLkUpVal();
    Page.CCPartnerBank = RefDataManager.GetPartnerBankLkUpVal();
    Page.CCDelStatus = RefDataManager.GetCardDelLkUpVal();
    Page.Solicitor = RefDataManager.GetSolicitorLkUpVal();
    Page.Rel2Ref = RefDataManager.GetRel2RefLkUpVal();
    Page.Campaign = RefDataManager.GetCampaignLkUpVal();
    Page.Month = RefDataManager.GetMonthLkUpVal();
    Page.Year = RefDataManager.GetYearLkUpVal();
    Page.CivilStatus = RefDataManager.GetCivilStatLkUpVal();
    Page.IDType = RefDataManager.GetIDTypeLkUpVal();
    Page.DesigRank = RefDataManager.GetDesRankLkUpVal();
    Page.NatureOfWork = RefDataManager.GetNatureOfWorkLkUpVal();
    Page.ModeOfRemit = RefDataManager.GetModeOfRemitLkUpVal();
    Page.CallFreq = RefDataManager.GetCallFreqLkUpVal();
    Page.CargoFreq = RefDataManager.GetCargoFreqLkUpVal();
    Page.RemitFreq = RefDataManager.GetRemitFreqLkUpVal();
    Page.ModeOfCall = RefDataManager.GetPrefModeOfComLkUpVal();
    Page.PrefModeOfComm = RefDataManager.GetPrefModeOfComLkUpVal();
    Page.PrefDayOfCall = RefDataManager.GetPrefDayLkUpVal();
    Page.PrefTimeOfCall = RefDataManager.GetPrefTimeLkUpVal();
    Page.RefBy = CustomerManager.GetAllCustomers();
    var ccStatus = RefDataManager.GetCashCardStatLkUpVal();
    var ccDocStatus = RefDataManager.GetDocStatLkUpVal();
    var ccType = RefDataManager.GetCashCardTypeLkUpVal();
    var ccPartnerBank = RefDataManager.GetPartnerBankLkUpVal();
    var ccDelStatus = RefDataManager.GetCardDelLkUpVal();
    var courierLkUp = CourierManager.GetCourierLkUpValues();
   
    //
    
    string currMailAdd1 = string.Empty;
    string currMailAdd2 = string.Empty;
    string permAdd1 = string.Empty;
    string permAdd2 = string.Empty;
    string busAdd1 = string.Empty;
    string busAdd2 = string.Empty;
    string mobileCC = string.Empty;
    string mobileAC = string.Empty;
    string mobileNo = string.Empty;
    string landLineCC = string.Empty;
    string landLineAC = string.Empty;
    string landLineNo = string.Empty;
    string workPCC = string.Empty;
    string workPAC = string.Empty;
    string workPNo = string.Empty;
    string srcOfFunds = string.Empty;
    string emp = string.Empty;
    string mor = string.Empty;
    string moc = string.Empty;
    string mocom = string.Empty;
    string prefDay = string.Empty;
    string prefTime = string.Empty;
    string allowContact = string.Empty;
    string gender=string.Empty;
    
    int sofctr=0;
    var defaultDate =string.Format("{0:M/d/yyyy}",new DateTime(1900,1,1));
    var custId=(Page.CustomerID!=null)?Page.CustomerID:string.Empty;
    var customer = (Page.Customer!=null)?Page.Customer:new Customer();
    var bDate = (Page.Customer.Bdate!=null)?String.Format("{0:M/d/yyyy}", customer.Bdate):"";  
    //var countryLkUp = RefDataManager.GetCountryValuesByRegion(customer.Region);
    var countryLkUp = RefDataManager.GetCountryValues();
    var stateLkUp = RefDataManager.GetStateValuesByCountry(customer.Country);
    
    
    if (bDate==defaultDate){
        bDate="";
    }
    var custRefBy="";
    foreach(var r in Page.RefBy){
        if(r.CustomerID.Equals(customer.ReferredBy)){
            custRefBy=r.FName + " " + r.LName;
        }
    }
   
    
    if(Page.Mode!="0"){
        string[] curMailAdd = customer.CurrMailAdd.Split('|');
        string[] permAdd=customer.PermAdd.Split('|');
        string[] busAdd=customer.BusAdd.Split('|');
        string[] mobileNum = customer.MobileNo.Split('|');
        string[] landNum = customer.LandLineNo.Split('|');
        string[] workPhone =customer.WorkPhone.Split('|');
        srcOfFunds = customer.SrcOfFunds;
        emp = customer.Employment;
        mor = customer.ModeOfRemit;
        moc = customer.ModeOfCall;
        mocom = customer.PrefModeOfComm;
        prefDay = customer.PreffCallDay;
        prefTime = customer.PrefCallTime;
        allowContact = customer.AllowContact;
        gender = customer.Gender;
        
        currMailAdd1 = (curMailAdd[0]!=null)?curMailAdd[0]:"";
        currMailAdd2 = (curMailAdd[1]!=null)?curMailAdd[1]:"";
        permAdd1 = (permAdd[0]!=null)?permAdd[0]:"";
        permAdd2 = (permAdd[1]!=null)?permAdd[1]:"";
        busAdd1 = (busAdd[0]!=null)?busAdd[0]:"";
        busAdd2 = (busAdd[1]!=null)?busAdd[1]:"";
        mobileCC = (mobileNum[0]!=null)?mobileNum[0]:"";
        mobileAC = (mobileNum[1]!=null)?mobileNum[1]:"";
        mobileNo = (mobileNum[2]!=null)?mobileNum[2]:"";
        landLineCC = (landNum[0]!=null)?landNum[0]:"";
        landLineAC = (landNum[1]!=null)?landNum[1]:"";
        landLineNo = (landNum[2]!=null)?landNum[2]:"";
        workPCC = (workPhone[0]!=null)?workPhone[0]:"";
        workPAC = (workPhone[1]!=null)?workPhone[1]:"";
        workPNo = (workPhone[2]!=null)?workPhone[2]:"";
       
   }else{
        string[] mobileNum = customer.MobileNo.Split('|');
        string[] landNum = customer.LandLineNo.Split('|');
        mobileAC = (mobileNum[1]!=null)?mobileNum[1]:"";
        mobileNo = (mobileNum[2]!=null)?mobileNum[2]:"";
        landLineAC = (landNum[1]!=null)?landNum[1]:"";
        landLineNo = (landNum[2]!=null)?landNum[2]:"";
}
    
    
    
    
    
    
    
    
    
}
<style type="text/css">
*{ font-family: Verdana; font-size: 96%; }
label { width: 15em; float: left; }
label.error { float: none; color: red; padding-left: .5em; vertical-align: top; }
p { clear: both; }
.submit { margin-left: 12em; }
em { font-weight: bold; padding-right: 1em; vertical-align: top; }

/*----disabled select**/
/*select[disabled] {
    color: black;
    background-color: while;
    border-style: solid;
}*/

select[disabled="disabled"] {background-color:#D4D0C8;} 
select[disabled="disabled"] option[selected="selected"] {background-color:navy;} 

/*autocomplete*/
/*#rBylabel {
		display: block;
		font-weight: bold;
		margin-bottom: 1em;
	}*/

 .customer {
    margin:0;
    padding:0;
    
}
 h1,h2 {
    margin:0;
}

.validateCC{
    float:left;
    margin:.5em;
}

</style>



<script>
    $(function(){
     
     $(".validation-error").hide();
   
    
//--------------dynamicall add/remove dialog buttons
    $.extend($.ui.dialog.prototype, { 
        'addbutton': function(buttonName, func) {	
                var buttons = this.element.dialog('option', 'buttons'); 
                buttons[buttonName] = func; 
                this.element.dialog('option', 'buttons', buttons); 
        } 
}); 

$.extend($.ui.dialog.prototype, { 
        'removebutton': function(buttonName) {	
                var buttons = this.element.dialog('option', 'buttons'); 
                delete buttons[buttonName]; 
                this.element.dialog('option', 'buttons', buttons); 
        } 
}); 
      




      
         wireEvents();   
      
        if(@Page.Mode=="0"){
            setDefaults();
        }else{
            setCustomerValues();
        }
        
         
        
       
        if(@Page.Mode=='1' || @Page.Mode=='3'){
             editModeOn()
        }
      
        if(@Page.Mode=='2'){
            $('#cash_card_form').dialog('open');
            $("#saveOption").val("2");
            $('#applyCC').val('APPLY FOR CASH CARD');
            
        }
        
        if(@Page.Mode=="4"){
             $('#tabs :input').removeAttr('disabled');
             cancelModeOn();
             $("addCustomer").val('SAVE');
             $('#applyCC').val('APPLY FOR CASH CARD');
             $("#saveOption").val("1");
             loadCCList("@customer.CustomerID");
        }
        
        
        if(@Page.Mode=='3'){
            loadCCList("@customer.CustomerID");
        }
        
        //set the dialogMessage
        getDialogMessage(@Page.Mode);
          //------Log elem values for auditing---//
        logElemValues();
        //logCCElemValues();    
    });
   function wireEvents(){
    
    //datepicker
    applyDatePicker("#datepicker");
    applyDatePicker("#appdate");
    applyDatePicker("#ccsdate");
    applyDatePicker("#ccexpdate");
    applyDatePicker("#delstatdate");
    applyDatePicker("#deldate");
    applyDatePicker("#sdate");
    applyDatePicker("#bdate");
    applyDatePicker("#ccbdate");
    
    //accordion personal info tab
   /*$( "#pi" ).accordion({
			//fillSpace:true,
            autoHeight:false,
           
            
		});*/
     
        
        
  /*$( "#tab3" ).resizable({
			minHeight: 100,
			resize: function() {
				$( "#pi" ).accordion( "resize" );
			}
		});*/
    
    
    //autocomplete referred by
    
    $("#rBy").autocomplete({
        source:getRefByDS(),
        minLength:0,
        focus: function( event, ui ) {
				$("#rBy").val( ui.item.label );
				return false;
			},
        select: function( event, ui ) {
    			$("#rBy").val( ui.item.label );
				$("#rByid").val( ui.item.value );
		        
				return false;
			}
            
    }).data("autocomplete")._renderItem = function( ul, item ) {
			return $( "<li></li>" )
				.data( "item.autocomplete", item )
				.append( "<a>" + item.label  + "</a>" )
				.appendTo( ul );
		};    
    
    
  
//-----dropdown country automatic country code
 
  $("select#country").bind("change",function(){
       var text = $("select#country option:selected").text();
        var value = $("select#country option:selected").val();
        if(text=="Philippines"){
            $("#mobileCC").val("63");
            $("#landLineCC").val("63");
            
        }else{
            $("#mobileCC").val("");
            $("#landLineCC").val("");
        }
    });
    
//------set CashCard status date to server date in Cashcard status is changed
$("select#cashCardStatus").change(function(){
      getServerDate("#ccsdate");
    
});

$("select#delStatus").change(function(){
      getServerDate("#sdate");
      getServerDate("#delstatdate");
});


$("select#cardType").change(function(){
    var text = $("select#cardType option:selected").text();
    var elem = $("#cardName");
    $("#cardName").empty();
    if(text=="Generic"){
        //set the Cutomer Name to MyRemit CashCard
         $("#cardName").val("MyRemit CashCard");
    }else{
        var data = getCustomerData();
         $("#cardName").val(data.FName + " " +data.MName +" "+ data.LName);
       // $("#cardName").val("@customer.FName @customer.MName @customer.LName");
    }
});
 
//-----------save dialog box
     $("#dialog").dialog({
         autoOpen:false,
         modal:true,
         resizable:false,
         draggable:false,
         position:"center",
         buttons:{
             "Yes, I do":function(){
                     //get all the fields to be submitted
                     //$("#custForm").submit();
                    logElemValues();
                    saveCustomer();
                   },
             "No":function(event){
                     $("#dialog").dialog("close");
                     event.preventDefault();
            }
        }
        });
        
//----------save and apply dialog        
        
//------------------apply cash card dialog
    $("#cash_card_form")
    //.load("/CashCardApp/CashCardForm.cshtml?custId="+$("#custId").val()) 
    .dialog({
        autoOpen:false,
        modal:true,
        height:600,
        width:800,
        resizable:false,
        draggable:true,
        position:"center",
        buttons:{
            "Save":{
                text:"Save",
                id:"ccSubmit",
                click:function(){
                $(this).parent().appendTo("#custForm");
                // logCCElemValues();
                 //logElemValues();
                 saveCashCard("0");
            }},
            "Cancel":function(event){
                $('#cash_card_form').dialog('close');
                 event.preventDefault();
            }
        }
    });
    //add dialog input elements to the main form
     $("#cash_card_form").parent().appendTo("#custForm");
 ///-----------------cash card detail form
  
  
//------------checkbox for Permanent address
   $("#chkSameAdd").click(function(){
       if($(this).is(":checked")){
           $("#permAdd1").val($("#currMailAdd1").val());
           $("#permAdd2").val($("#currMailAdd2").val());
           $("#permAddCity").val($("#currMailCity").val());
           $("#permAddCountry").val($("#currMailCountry").val());
           $("#permAddState").val($("#currMailState").val());
           $("#permAddZip").val($("#currMailZip").val());
        
       } else{
          //alert("unchecked"); 
       }
   });
    
//-----------------------------save button  
     
      $("#addCustomer").click(function(){
          //set dialog box message
          var saveOption =  $("#saveOption").val(); 
          if(saveOption==""){
             saveOption="0";
          }
           getDialogMessage(saveOption);
        
           if ($(this).val()=='SAVE'){
             if(validateForm()){
               $("#dialog").dialog("open");
               $("#saveOption").val("0"); 
            }
          }else if($(this).val()=='EDIT'){
            $('#tabs :input').removeAttr('disabled');
            cancelModeOn();
             $(this).val('SAVE');
            $("#saveOption").val("1"); 
        }
           
       });
//----------cancel customer form---------------//
  $("#cancel").click(function(){
    cancelCustForm();
});
//-------------- apply cashcard button
      $("#applyCC").click(function(){
          var btn = $(this).val();
        if(btn=='SAVE AND APPLY FOR CASH CARD'){
            if(validateForm()){
             $("#dialog").dialog("open");
             $("#saveOption").val("1");
            }
        }else if(btn=='APPLY FOR CASH CARD'){
             openCashCardForm();
             $("#saveOption").val("2");
        }
      
     });
    
    
//------------Fill the customer drop down
      /*GetLookUp('#region','#country','country');    
      GetLookUp('#region','#currMailCountry','country');
      GetLookUp('#region','#permAddCountry','country');
      GetLookUp('#region','#busAddCountry','country');*/
      GetLookUp('#country','#curState','state');
      GetLookUp('#country','#permAddState','state');
      GetLookUp('#country','#busAddState','state');
      GetLookUp('#country','#currMailState','state');
    
    //cachcard list
    $("#ccList").tabs();
    
    //Save Customer service

}

function saveCustomer(){
   try{  
    var data = $("#custForm").serialize();
   /* $.post("/Customer/Services/CustomerService/save",data,
        function(data){
          editModeOn();
          setCustomerData(data[0]);
          $('#tabs').tabs('select', '1');
          $("#dialog").dialog("close");
          $("#lblCustID").html(data[0].CustomerID);
          $("#lblBigCustID").html(data[0].CustomerID);
          $("#custId").val(data[0].CustomerID);
          $("#cID").val(data[0].CustomerID);
        //check saveOption
          var so = $("#saveOption").val();
          if(so=='1'){
            //open cashcard form 
            openCashCardForm();
            $("#saveOption").val("2");
          }
    },"json");*/
    
    
     $.ajax({
            url:"/Customer/Services/CustomerService/save",
            async:false,
            data:data,
            cache:false,
            dataType:'json',
            success: function(data){
                   editModeOn();
                    setCustomerData(data[0]);
                    $('#tabs').tabs('select', '1');
                   // $('#accordion').accordion({active:"#tab3h3-1"});
                    $("#dialog").dialog("close");
                    $("#lblCustID").html(data[0].CustomerID);
                    $("#lblBigCustID").html(data[0].CustomerID);
                    $("#custId").val(data[0].CustomerID);
                    $("#cID").val(data[0].CustomerID);
                    //check saveOption
                    var so = $("#saveOption").val();
                    if(so=='1'){
                        //open cashcard form 
                        openCashCardForm();
                        $("#saveOption").val("2");
                    }
                 
            }});
    
    }catch(e){
        alert(e);
    }
}


function openCashCardForm(){
    /*$.post("/Customer/Services/CustomerService/nextccid/"+$("#custId").val(),
        function(data){
            $("#lblCCID").html(data[0]);
            $("#ccId").val(data[0]);
            $("#cID").val($("#custId").val());
            clearForm("#ccForm");
            setCCDefaults();
            $("#cash_card_form :input").removeAttr('disabled');
            dialogCCSaveMode(createCashCard);
    },"json");*/
       $("#lblCCID").empty();
      $("#cID").val($("#custId").val());
      clearForm("#ccForm");
      setCCDefaults();
      $("#cash_card_form :input").removeAttr('disabled');
     
     
      dialogCCSaveMode(createCashCard);
      
}

function saveCashCard(mode){
    logCCElemValues();
    var ccform = $("#ccForm").serialize();
    var cform = $("#custForm").serialize();
    cform+="&"+ccform;
    
    if(validateCCForm()){
        $.post("/Customer/Services/CustomerService/savecc/"+mode,ccform,
            function(data){
                $('#cash_card_form').dialog('close');
                showMessage("Cash card saved");
                var customer=data[0];
                var ccList = data[1];
                refreshCustomerData();
                loadCCList($("#custId").val());  
        },"json");
    }
     
}




function loadCCList(id){
    //var cid=$("#custId").val();
    $("#grid").empty();
    //$("#grid").load("/Customer/CashCardGrid/"+id);
    //test ie
    
  /*  var dummy = new Date().getTime();
    $.get("/Customer/CashCardGrid/"+id+"/"+dummy,function(data){
        $("#grid").html(data); 
    });*/
    
     var dummy = new Date().getTime();
    $.get("/Customer/CashCardGridNew/"+id+"/"+dummy,function(data){
        $("#grid").html(data); 
    });
    
    
}

function editCC(id,mode){
    //alert(id);
    //get cc details and set fields 
     $.post("/Customer/Services/CustomerService/getcc/"+id,
        function(data){
            var ccData = data[0];
            //fillup cc form with details
            var appDate = ccData.ApplicationDate;
            var sDate = ccData.StatusDate;
            var ccSDate = ccData.CashCardStatusDate;
            var expDate = ccData.CardExpDate;
            var delDate = ccData.DelDate;
            var delStatDate = ccData.DelStatusDate;
            $("#lblCCID").html(id);
            $("#ccId").val(id);
            $("#appdate").val(formatJSONDate(appDate));
            //$("#sdate").val(formatJSONDate(sDate));
            $("#ccsdate").val(formatJSONDate(ccSDate));
            //check delivery data and exp date 
            //if value is 1/1/1900 dont display
            var expD = formatJSONDate(expDate);
            var delD = formatJSONDate(delDate);
            
            $("#ccexpdate").val((expD==defaultDate())?"":expD);
            $("#deldate").val((delD==defaultDate())?"":delD);
            $("#delstatdate").val(formatJSONDate(delStatDate));
            //$("select#cashCardStatus").val(ccData.CashCardStatus);
             $("select#cashCardStatus").find("option[value='"+ccData.CashCardStatus+"']").attr("selected",true);
    
            $("select#docStatus").find("option[value='"+ccData.DocumentStatus+"']").attr("selected",true);
            $("#ccno").val(ccData.CashCardNo);
            $("select#cardType").find("option[value='"+ccData.CashCardType+"']").attr("selected",true);
            $("#partnerBank").val(ccData.PartnerBank);
            $("#cardName").val(ccData.NameOnCard);
            //$("select#delStatus").val(ccData.CardDelStatus);
            $("select#delStatus").find("option[value='"+ccData.CardDelStatus+"']").attr("selected",true);
    
            $("#remarks").val(ccData.Remarks);
            $("#dremarks").val(ccData.DelRemarks);
            
            $("select#courier").find("option[value='" + ccData.CardDelCourier +"']").attr("selected",true);
            
            //get customer data
            getCustomerCCData();
            //logCCElemValues();
            if(mode=="0"){
              $("#cash_card_form :input").attr('disabled',true);
              dialogCCUpdateMode(editCashCardDetails);     
            }else{
                $("#cash_card_form :input").removeAttr('disabled');
                dialogCCSaveMode(updateCashCard); 
            }
            
           
            
              
    },"json");
}

function editCashCardDetails(){
    $("#cash_card_form :input").removeAttr('disabled');
    dialogCCSaveMode(updateCashCard);
}

function updateCashCard(){
    saveCashCard("1");
}

function createCashCard(){
    saveCashCard("0");
}

function dialogCCUpdateMode(f){
     $("#cash_card_form").dialog("open");
     
     $('#cash_card_form').dialog('removebutton', 'Save');
     $('#cash_card_form').dialog('addbutton', 'Edit', f); 
            
}

function dialogCCSaveMode(f){
    $("#cash_card_form").dialog("open");
    //setCCDefaults();
    $('#cash_card_form').dialog('removebutton', 'Edit');
    $('#cash_card_form').dialog('addbutton', 'Save', f);
}

function formatJSONDate(jsonDate){
    var newDate =  new Date(parseInt(jsonDate.substr(6)));
    return formatDate(newDate);

}

function formatDate(value)
{
  var mm = value.getMonth()+1;
  var dd = value.getDate();
  var yyyy = value.getFullYear();
  if(dd<10){dd='0'+dd}
  if(mm<10){mm='0'+mm}
  return mm + "/" + dd + "/" + yyyy;
}

function validateAge(value){
    var year =value.getFullYear();
    var today = new Date();
    var age = today.getFullYear()-year;
    if(age>15){
        return true;
    }else{
        return false;
    }
}


function clearForm(form) {
  // iterate over all of the inputs for the form
  // element that was passed in
  $(':input', form).each(function() {
    var type = this.type;
    var tag = this.tagName.toLowerCase(); // normalize case
    // it's ok to reset the value attr of text inputs,
    // password inputs, and textareas
    if (type == 'text' || type == 'password' || tag == 'textarea')
      this.value = "";
    // checkboxes and radios need to have their checked state cleared
    // but should *not* have their 'value' changed
    else if (type == 'checkbox' || type == 'radio')
      this.checked = false;
    // select elements need to have their 'selectedIndex' property set to -1
    // (this works for both single and multiple select elements)
    else if (tag == 'select')
      this.selectedIndex = -1;
  });
};



function validateForm(){
     $("#message").empty();
    
    var fname = $("#fname").val();
    var mname = $("#mname").val();
    var lname = $("#lname").val();
    var pob =$("#pob").val();
    var idNo = $("#idNo").val();
    var busName =$("#busName").val();
    var bDate =$("#bdate").val();
    var genderm = $("#radio-m").is(':checked');
    var genderf = $("#radio-f").is(':checked');
    var mNo = $("#mobileNo").val();
    var mCC = $("#mobileAC").val();
    var mAC = $("#mobileCC").val();
    var llNo = $("#landLineNo").val();
    var llCC = $("#landLineCC").val();
    var llAC = $("#landLineAC").val();
    var cma1 = $("#currMailAdd1").val();
    var cma2 = $("#currMailAdd2").val();
    var cmCity = $("#currMailCity").val();
    var cmCountry = $("#currMailCountry").val();
    var cmState = $("#currMailState").val();
    
    
    
    var mValid=false;
    var llValid=false;
    
    
    
    //hide error labels
     $(".validation-error").hide();
    if(fname==""){
      //$("label#fname_error").show();
      errorCssOn("input#fname");
      $("input#fname").focus();
      showErrorMessage("Customer first name is required");
      $('#tabs').tabs('select', '3');
      $('#personal_accordion').accordion({active:"#tab3h3-1"});
      return false;  
    }else{
       errorCssOff("input#fname"); 
    }
    
    if(mname==""){
      //$("label#mname_error").show();  
      $("input#mname").focus();
      errorCssOn("input#mname");
      $('#personal_accordion').accordion({active:"#tab3h3-1"});
      showErrorMessage("Customer middle name is required");
      $('#tabs').tabs('select', '3');
      return false;  
    }else{
          errorCssOff("input#mname");
    }
    
    if(lname==""){
      //$("label#lname_error").show();
      errorCssOn("input#lname");
      $("input#lname").focus();  
      showErrorMessage("Customer last name is required");
      $('#tabs').tabs('select', '3');
      $('#personal_accordion').accordion({active:"#tab3h3-1"});
      return false;  
    }else{
         errorCssOff("input#lname");
    }
    
    if(!genderm && !genderf){
        //$("label#gender_error").show();
        errorCssOn("#gender_container");
        showErrorMessage("Gender is required");
        $("#tabs").tabs("select","3");
        $('#personal_accordion').accordion({active:"#tab3h3-1"});
        return false;
    }else{
         errorCssOff("#gender_container");
    }
    /*if(bDate==""){
      $("label#bdate_error").show();  
      $("input#bdate").focus();  
      showErrorMessage("Customer birthday is required");
      $('#tabs').tabs('select', '3');
      return false;  
    }*/
  
    /*if(pob==""){
      $("label#pob_error").show();  
      $("input#pob").focus();  
      showErrorMessage("Customer place of birth is required");
      $('#tabs').tabs('select', '3');
      return false;  
    }*/
    
    if( mCC=="" || mAC=="" || mNo==""){
        mValid=false;
    }else{
        mValid=true;
    }
    
    if(llCC=="" || llAC=="" || llNo==""){
        llValid=false;
    }else{
        llValid=true;
    }
    
    if(!mValid && !llValid){
        //$("label#phoneNo_error").show(); 
        errorCssOn("#phone_countainer");
        showErrorMessage("At least one phone number is required");
        $('#tabs').tabs('select', '3');
         $('#personal_accordion').accordion({active:"#tab3h3-2"});
        return false;
    }else{
        errorCssOff("#phone_countainer");
    }
    
    var cma1 = $("#currMailAdd1").val();
    var cma2 = $("#currMailAdd2").val();
    var cmCity = $("#currMailCity").val();
    var cmCountry = $("#currMailCountry").val();
    
    if(cma1==""){
         //$("label#currMailAdd1_error").show();
         errorCssOn("#currMailAdd1");
         showErrorMessage("Current mail address  is required");
         $('#tabs').tabs('select', '3');
         $('#personal_accordion').accordion({active:"#tab3h3-3"});
         return false;
    }else{
         errorCssOff("#currMailAdd1");
    }
    
    if(cma2==""){
         //$("label#currMailAdd2_error").show(); 
         errorCssOn("#currMailAdd2");
         showErrorMessage("Current mail address  is required");
         $('#tabs').tabs('select', '3');
         $('#personal_accordion').accordion({active:"#tab3h3-3"});
         return false;
    }else{
         errorCssOff("#currMailAdd2");
    }
    
    if(cmCity==""){
         //$("label#currMailCity_error").show(); 
         errorCssOn("#currMailCity");
         showErrorMessage("Current mail city  is required");
         $('#tabs').tabs('select', '3');
         $('#personal_accordion').accordion({active:"#tab3h3-3"});
         return false;
    }else{
        errorCssOff("#currMailCity");
    }
    
    if(cmCountry==""){
         //$("label#currMailCountry_error").show(); 
         errorCssOn("#currMailCountry");
         showErrorMessage("Current mail country  is required");
         $('#tabs').tabs('select', '3');
         $('#personal_accordion').accordion({active:"#tab3h3-3"});
         return false;
    }else{
        errorCssOff("#currMailCountry");
    }
    
    
    if(cmState==""){
         //$("label#currMailCountry_error").show(); 
         errorCssOn("#currMailState");
         showErrorMessage("Current mail state  is required");
         $('#tabs').tabs('select', '3');
         $('#personal_accordion').accordion({active:"#tab3h3-3"});
         return false;
    }else{
        errorCssOff("#currMailState");
    }
  /*  if(idNo==""){
      $("label#idNo_error").show();  
      $("input#idNo").focus();  
      return false;  
    }*/
    
    /*if(busName==""){
      $("label#busName_error").show();  
      $("input#busName").focus();  
      return false;  
    }*/
    
    
    
    return true;
    
    
}

function validateCCForm(){
    var bDate =$("#ccbdate").val();
    var appDate = $("#appdate").val();
    var ccsDate = $("#ccsdate").val();
    var ccExpDate =$("#ccexpdate").val();
    var delStatDate = $("#delstatdate").val();
    var sDate = $("#sdate").val();
    var delDate = $("#deldate").val();
    var rem = $("#remarks").val();
    var delStatus = $("select#delStatus").val();
    var pob =$("#ccpob").val();
    var civilStatus = $("#cc_cstatus").val();
    var idNo = $("#ccidNo").val();
    var idType =$("#ccidType").val();
    var sof = $("#ccsrcOfFunds option:selected").length;
    var employer=$("#ccbusName").val();
    var now = $("#ccnatureOfWork").val();
    //customer
    var customer = getCustomerData();
   
     $(".validation-error").hide();
    
    if(civilStatus=="default"){
      $("label#cc_cstatus_error").show();  
      $("input#cc_cstatus").focus();  
      errorCssOn("#cc_cstatus");
     
      return false;  
    }else{
        errorCssOff("#cc_cstatus");
    }
    
    /*if(idType=="default"){
      $("label#ccidType_error").show();  
      $("input#ccidType").focus();  
      return false;  
    }
    
     if(idNo==""){
      $("label#ccidNo_error").show();  
      $("input#ccidNo").focus();  
      return false;  
    }*/
    
    if(bDate==""){
      $("label#ccbdate_error").show();  
      $("input#ccbdate").focus();  
       errorCssOn("#ccbdate");
      return false;  
    }else{
         errorCssOff("#ccbdate");
        //check age
        var bd = new Date(bDate);
        if( !validateAge(bd)){
            $("label#ccbdate_age_error").show();  
            $("input#ccbdate").focus();
            errorCssOn("#ccbdate");
            return false;
        }else{
            errorCssOff("#ccbdate");
  
        }
    }
    
    if(pob==""){
      $("label#ccpob_error").show();  
      $("input#ccpob").focus();
       errorCssOn("#ccpob");
  
      return false;  
    }else{
         errorCssOff("#ccpob");
    }
    
    if(!sof){
        $("label#ccsrcOfFunds_error").show();
        $("input#ccsrcOfFunds").focus();
         errorCssOn("#ccsrcOfFunds");
        return false;
    }else{
        errorCssOff("#ccsrcOfFunds");
    }
    
    var emp = customer.Employment.split(',');
   
    var isEmployed;
    for(var x in emp){
        if(emp[x]=="10" || emp[x]=="20"){
            isEmployed=true;
        }
    }

    if(isEmployed==true){
        //validate employer and nature of work
        if(employer==""){
            $("label#ccbusName_error").show();
            $("#ccbusName").focus();
            errorCssOn("#ccbusName");
            return false;
        }else{
            errorCssOff("#ccbusName");
        }
       
        if(now==""){
             $("label#ccnatureOfWork_error").show();
             $("#ccnatureOfWork").focus();
             errorCssOn("#ccnatureOfWork");
            return false;
        }else{
             errorCssOff("#ccnatureOfWork");
 
        }
    }
    
    
    
    
    
    if(appDate==""){
        $("label#appdate_error").show();
        $("input#appdate").focus();
        errorCssOn("#appdate");
 
        return false;
    }else{
        errorCssOff("#appdate");
 
    }
    
    if(ccsDate==""){
        $("label#ccsdate_error").show();
        $("input#ccsdate").focus();
        errorCssOn("#ccsdate");
        return false;
    }else{
         errorCssOff("#ccsdate");
   }
    
   /* if(sDate==""){
        $("label#sdate_error").show();
        $("input#sdate").focus();
        return false;
    }*/
    //if delivery status is Undelivered or Cancelled remarks is required
    if(delStatus=="ud" || delStatus=="cancelled"){
       if(rem==""){
        $("label#remarks_error").show();
        $("input#remarks").focus();
        errorCssOn("input#remarks");

        return false;
      }else{
        errorCssOff("input#remarks");

      }     
    }
    
    /*if(ccExpDate==""){
        $("label#ccexpdate_error").show();
        $("input#ccexpdate").focus();
        return false;
    }
    
   if(delStatDate==""){
        $("label#delstatdate_error").show();
        $("input#delstatdate").focus();
        return false;
    }
    
   if(delDate==""){
        $("label#deldate_error").show();
        $("input#deldate").focus();
        return false;
    }*/
    return true;
    
    
}

function setDefaults(){
    //set classification to In-PH
    //set customer status to lead
    //set region to Philippines
    //set nationality to Filipino
    //set Country to Philippines
    //cancel button disabled
    $("select#custClass").find("option#In-PH").attr("selected", true);
    $("select#custStatus").find("option#Lead").attr("selected", true);
    $("select#region").find("option#Philippines").attr("selected", true);
    $("select#country").find("option#PH").attr("selected", true);
    $("select#currMailCountry").find("option#PH").attr("selected", true);
    $("select#permAddCountry").find("option#PH").attr("selected", true);
    
    
    $("select#nationality").find("option#Filipino").attr("selected", true);
    //country to philippines
    var region = $("select#region").val();
    //setLookUp(region,"country","country");
    //setLookUp(region,'currMailCountry','country');
    //setLookUp(region,'permAddCountry','country');
    setLookUp(region,'busAddCountry','country');
    
    //cashcard defaults
    $("#cancel").attr("disabled",true);
   
   //if country is philippines set phone country code to 63
   var text = $("select#country option:selected").text();
   
    if(text=="Philippines"){
        $("#mobileCC").val("63");
        $("#landLineCC").val("63");
        
    }else{
        $("#mobileCC").val("");
        $("#landLineCC").val("");
    }
    
   $("#mobileAC").val(@mobileAC);
   $("#mobileNo").val(@mobileNo);
   $("#landLineAC").val(@landLineAC);
   $("#landLineNo").val(@landLineNo);

}

function defaultDate(){
    return "01/01/1900";
}

function getCustomerCCData(){
     var data = getCustomerData();
     var bdate = formatJSONDate(data.Bdate);
      if(bdate!=defaultDate()){
      $("#ccbdate").val(bdate);
    }
    
      $("#ccpob").val(data.PlaceOfBirth);
    if(data.CivilStatus.length>0 && data.CivilStatus!="default"){
         $("select#cc_cstatus").find("option#"+data.CivilStatus).attr("selected", true);
    }else{
         $("select#cc_cstatus").find("option#default_cs").attr("selected", true);
    }
  
    if(data.IDType!="" && data.IDType!='default'){
          $("select#ccidType").find("option#"+data.IDType).attr("selected", true);  
    }else{
        $("select#ccidType").find("option#default_idType").attr("selected", true); 
    }
   
    $("#ccidNo").val(data.IDNumber);
    
     //source of funds,employer and nature of work
   var sofs =data.SrcOfFunds.split(',');
   if(sofs!=""){
    for(var i=0;i<sofs.length;i++){
        $("select#ccsrcOfFunds").find("option#"+sofs[i]).attr("selected", true);  
    }
  }
   
   $("#ccbusName").val(data.Employer);

   if(data.NatureOfWork!=""){
          $("select#ccnatureOfWork").find("option#"+data.NatureOfWork).attr("selected", true);  
    }else{
        $("select#ccnatureOfWork").find("option#default_ccnow").attr("selected", true); 
    }
    var cardName = $("#cardName").val();
    if(cardName==""){
       $("#cardName").val(data.FName +" "+data.MName+" "+data.LName); 
    }
       
    logCCElemValues();
}

function setCCDefaults(){
    getCustomerCCData();
    
    $("select#cashCardStatus").find("option#New").attr("selected",true);
    $("select#docStatus").find("option#Incomplete").attr("selected",true);
    $("select#cardType").find("option#Personalized").attr("selected",true);
    $("select#delStatus").find("option#Pending").attr("selected",true);
    $("select#partnerBank").find("option#CT").attr("selected",true);
  
    
    getServerDate("#appdate");
    getServerDate("#ccsdate");
    getServerDate("#delstatdate");
    //$("#cardName").val("@customer.FName @customer.MName  @customer.LName");    
 
}

function setCustomerValues(){
   var sof = "@srcOfFunds";
   var emp = "@emp";
   var mor = "@mor";
   var moc = "@moc";
   var mocom = "@mocom";
   var prefDay = "@prefDay";
   var prefTime ="@prefTime";
   var allowContact="@allowContact";
   
   var sofs = sof.split(',');
   if(sofs!=""){
    for(var i=0;i<sofs.length;i++){
        $("select#srcOfFunds").find("option#"+sofs[i]).attr("selected", true);  
    }
  }

   var emps = emp.split(',');
   if(emps!=""){
    for(var a=0;a<emps.length;a++){
        $("select#employment").find("option#"+emps[a]).attr("selected", true);    
    }
  }
   var mors = mor.split(',');
   if(mors!=""){
   for(var b=0;b<mors.length;b++){
       $("select#modeOfRemit").find("option#"+mors[b]).attr("selected", true);    
   }
  }
   var mocs= moc.split(',');
   if(mocs!=""){
    for(var c=0;c<mocs.length;c++){
        $("select#modeOfCall").find("option#"+mocs[c]).attr("selected", true);    
    }
 }
   var mocoms = mocom.split(',');
   if(mocoms!=""){
    for(var d=0;d<mocoms.length;d++){
        $("select#prefModeOfComm").find("option#"+mocoms[d]).attr("selected", true);    
    }
  }
   var prefDays = prefDay.split(',');
   if(prefDays!=""){
    for(var e=0;e<prefDays.length;e++){
        $("select#prefCallDay").find("option#"+prefDays[e]).attr("selected", true);    
    }
   }
   var prefTimes= prefTime.split(',');
   if(prefTimes!=""){
    for(var f=0;f<prefTimes.length;f++){
       $("select#prefCallTime").find("option#"+prefTimes[f]).attr("selected", true);    
   }
 }
   
   var atcs= allowContact.split(',');
   if(atcs!=""){
   for(var g=0;g<atcs.length;g++){
       var elem = "#chk-"+atcs[g];
       $(elem).prop("checked",true);    
   }
 }
  
   //gender
   var gender = "#radio-@gender";
   if(gender!=""){
     $(gender).prop("checked",true);
   }
}








function disableCCDates(){
    $("#appdate").attr('disabled',true);
    $("#ccsdate").attr('disabled',true);
    $("#ccexpdate").attr('disabled',true);
    $("#delstatdate").attr('disabled',true);
    $("#deldate").attr('disabled',true);
    $("#sdate").attr('disabled',true);
}
function enableCCDates(){
    $("#appdate").removeAttr('disabled');
    $("#ccsdate").removeAttr('disabled');
    $("#ccexpdate").removeAttr('disabled');
    $("#delstatdate").removeAttr('disabled');
    $("#deldate").removeAttr('disabled');
    $("#sdate").removeAttr('disabled');
}
//for Referred by autocomplete
function getRefByDS(){
      var refList = {};
      $.ajax({
            url:"/Customer/Services/CustomerService/referby",
            async:false,
            cache:false,
            dataType:'json',
            success: function(data){
                    var refData = data;
                    $.each(refData, function(key,value) {
                        var refBy = refData[0];
                        refList=refData[0];
                    });
            }
         });
       
       return refList;
    
}

function showMessage(message){
    $('#message').html("<p class='message info'>"+message+"</p>");
    window.setTimeout(hideMessage,5000);
    
}

function showErrorMessage(message){
    $('#message').html("<p class='message error'>"+message+"</p>");
    window.setTimeout(hideMessage,5000);
}


function hideMessage(){
    $("#message").empty();
}

function getServerDate(elem){
     var dummy = new Date().getTime();
     $.get("/Customer/Services/CustomerService/getserverdate/"+dummy,function(data){
        var date=new Date(data[0]);
        $(elem).val(formatDate(date)); 
    },"json");
    
}

function logElemValues(){
    var str="";
    var size=$("#tabs input").length;
    var ctr=0;
    var delimiter="|";
    $.each($("#tabs :input"),function(i,e){
      
        //alert("Name="+e.id + "value="+e.value);
        $.data(e,"old", $.data(e,"new")||"");
        $.data(e,"new", e.value);
        //alert("id="+e.id+"\nOld:"+$.data(e,"old") + "\nNew:" + $.data(e,"new"));
        var oldVal = $.data(e,"old");
        var newVal = $.data(e,"new");
       //alert(e.name+"\nold=" + oldVal +"\n new="+ newVal);
       if(oldVal!=newVal){
          ctr++;
         
         if(ctr==1){
            str+=e.name+","+oldVal+","+newVal;
          }else{
             str+=delimiter+e.name+","+oldVal+","+newVal;
          }
         
            
        }
        
    });
  
    //alert("changeValues="+str);
    $("#changeFormVal").val(str);
    //alert( $("#changeFormVal").val());
}

function logCCElemValues(){
    var strCC="";
    //var size=$("#cash_card_form input").length;
    var delimiter="|";
    var ctr=0;
   
    $.each($("#cash_card_form :input"),function(i,e){
      
        //alert("Name="+e.id + "value="+e.value);
        $.data(e,"oldCC", $.data(e,"newCC")||"");
        $.data(e,"newCC", e.value);
        //alert("id="+e.id+"\nOld:"+$.data(e,"old") + "\nNew:" + $.data(e,"new"));
        var oldVal = $.data(e,"oldCC");
        var newVal = $.data(e,"newCC");
       // alert("olCCValue="+oldVal+"\n newCCValue="+newVal);
      if(oldVal!=newVal){
        if(e.name!="changeCCData"){
          ctr++;
           // alert(e.name);
            if(ctr==1){
              strCC+=e.name+","+oldVal+","+newVal;
            }else{
                strCC+=delimiter+e.name+","+oldVal+","+newVal;
            }
          }
          
            
       }
        
    });
  
   // alert("CC-ChangeValues="+ $("#changeCCData").val());
   
    $("#changeCCData").val(strCC);
    
}

function cancelCustForm(){
    //set customer form values to their original values
    //get customer details
    refreshCustomerData();
    editModeOn();
}



function setCustomerData(data){
    var curMailAdd = data.CurrMailAdd.split('|');
    var permAdd=data.PermAdd.split('|');
    var busAdd=data.BusAdd.split('|');
    var mobileNum = data.MobileNo.split('|');
    var landNum = data.LandLineNo.split('|');
    var workPhone =data.WorkPhone.split('|');
    var currMailAdd1 = (curMailAdd[0]!=null)?curMailAdd[0]:"";
    var currMailAdd2 = (curMailAdd[1]!=null)?curMailAdd[1]:"";
    var permAdd1 = (permAdd[0]!=null)?permAdd[0]:"";
    var permAdd2 = (permAdd[1]!=null)?permAdd[1]:"";
    var busAdd1 = (busAdd[0]!=null)?busAdd[0]:"";
    var busAdd2 = (busAdd[1]!=null)?busAdd[1]:"";
    var mobileCC = (mobileNum[0]!=null)?mobileNum[0]:"";
    var mobileAC = (mobileNum[1]!=null)?mobileNum[1]:"";
    var mobileNo = (mobileNum[2]!=null)?mobileNum[2]:"";
    var landLineCC = (landNum[0]!=null)?landNum[0]:"";
    var landLineAC = (landNum[1]!=null)?landNum[1]:"";
    var landLineNo = (landNum[2]!=null)?landNum[2]:"";
    var workPCC = (workPhone[0]!=null)?workPhone[0]:"";
    var workPAC = (workPhone[1]!=null)?workPhone[1]:"";
    var workPNo = (workPhone[2]!=null)?workPhone[2]:"";
    
    var fname = data.FName;
    var mname = data.MName;
    var lname = data.LName;
    var bdate = data.Bdate;
    var pob = data.PlaceOfBirth;
    var employer = data.Employer;
    
    var custClass = data.CustomerClassification;
    var custStatus = data.CustomerStatus;
    var region = data.Region;
    var solicitor = data.Solicitor;
    var campaign = data.Campaign;
    var rel2ref = data.RelationshipToReferror;
    var country = data.Country;
    var monArr = data.MonthArrived;
    var yearArr = data.YearArrived;
    var nat = data.Nationality;
    var civilStatus = data.CivilStatus;
    var idType = data.IDType;
    var idNo = data.IDNumber;
    var cCountry = data.CurrMailCountry;
    var cState = data.CurrMailState;
    var pCountry = data.PermAddCountry;
    var pState = data.PermAddState;
    var designation = data.Designation;
    var now = data.NatureOfWork;
    var bCountry = data.BusAddCountry;
    var bState  = data.BusAddState;
    var callF = data.CallFrequency;
    var cargoF = data.CargoFrequency;
    var remitF = data.RemitFrequency;
    

    var sof = data.SrcOfFunds;
    var emp = data.Employment;
    var mor = data.ModeOfRemit;
    var moc = data.ModeOfCall;;
    var mocom = data.PrefModeOfComm;
    var prefDay = data.PreffCallDay;
    var prefTime =data.PrefCallTime;
    var allowContact=data.AllowContact;
    var notes = data.Notes;
    
    //customer header
   $("#lblCustomerHeader").empty(); 
   $("#lblCustomerHeader").html("Customer:"+fname + " " + lname); 
   
   $("#fname").val(fname);
   $("#mname").val(mname);
   $("#lname").val(lname);
   $("#pob").val(pob);
   $("#bdate").val(formatJSONDate(bdate));
   $("#currMailAdd1").val(currMailAdd1); 
   $("#currMailAdd2").val(currMailAdd2);
   $("#permAdd1").val(permAdd1);
   $("#permAdd2").val(permAdd2);
   $("#bussAdd1").val(busAdd1);
   $("#bussAdd2").val(busAdd2);
   $("#mobileCC").val(mobileCC);
   $("#mobileAC").val(mobileAC);
   $("#mobileNo").val(mobileNo);
   $("#landLineCC").val(landLineCC);
   $("#landLineAC").val(landLineAC);
   $("#landLineNo").val(landLineNo);
   $("#busPhoneCC").val(workPCC);
   $("#busPhoneAC").val(workPAC);
   $("#busPhoneNo").val(workPNo);
   $("#busName").val(employer);

   
   
   //drop downs controls
    if(custClass!=""){
         $("select#custClass").find("option#"+custClass).attr("selected", true);  
    }else{
         $("select#custClass").find("option#In-PH").attr("selected", true); 
    }
    if(custStatus!=""){
          $("select#custStatus").find("option#"+custStatus).attr("selected", true);  
    }
    if(region!=""){
          $("select#region").find("option#"+region).attr("selected", true);  
    }else{
        $("select#region").find("option#Philippines").attr("selected", true);
    }
    if(solicitor!=""){
         $("select#solicitor").find("option#"+solicitor).attr("selected", true);  
    }else{
         $("select#solicitor").find("option#default_solicitor").attr("selected", true);  
    }
    if(campaign!=""){
         $("select#campaign").find("option#"+campaign).attr("selected", true); 
    }else{
          $("select#campaign").find("option#default_campaign").attr("selected", true); 
    }
    if(rel2ref!=""){
         $("select#rel2ref").find("option#"+rel2ref).attr("selected", true);  
    }else{
        $("select#rel2ref").find("option#default_r2r").attr("selected", true);   
    }
    if(country!=""){
         $("select#country").find("option#"+country).attr("selected", true);  
    }else{
        $("select#country").find("option#Philippines").attr("selected", true);
    }
    if(monArr!=""){
        $("select#monArr").find("option#"+monArr).attr("selected", true);  
    }else{
        $("select#monArr").find("option#ma").attr("selected", true);
    }
    if(yearArr!=""){
        $("select#yrArr").find("option#"+yearArr).attr("selected", true);  
    }else{
         $("select#yrArr").find("option#ya").attr("selected", true);
    }
    if(nat!=""){
          $("select#nationality").find("option#"+nat).attr("selected", true);  
    }
    if(civilStatus!="default"){
         $("select#civilStatus").find("option#"+civilStatus).attr("selected", true);
    }else{
         $("select#civilStatus").find("option#default_cs").attr("selected", true);
    }
    if(idType!="default"){
          $("select#idType").find("option#"+idType).attr("selected", true);  
    }else{
        $("select#idType").find("option#default_idType").attr("selected", true); 
    }
    
   /* if(idNo!=""){
          $("#idNo").val(idNo);  
    }*/
    
    $("#idNo").val(idNo);
    
    if(cCountry!=""){
         $("select#currMailCountry").find("option#"+cCountry).attr("selected", true);  
    }
    if(cState!=""){
         $("select#currMailState").find("option#"+cState).attr("selected", true);  
    }else{
        $("select#currMailState").find("option#default_cstate").attr("selected", true);
    }
    if(pCountry!=""){
         $("select#permAddCountry").find("option#"+pCountry).attr("selected", true);  
    }
    if(pState!=""){
         $("select#permAddState").find("option#"+pState).attr("selected", true); 
    }else{
        $("select#permAddState").find("option#default_pstate").attr("selected", true); 
    }
    if(designation!=""){
         $("select#desigRank").find("option#"+designation).attr("selected", true); 
    }
    if(now!=""){
        $("select#natureOfWork").find("option#"+now).attr("selected", true); 
    }
    if(bCountry!=""){
         $("select#busAddCountry").find("option#"+bCountry).attr("selected", true); 
    }
    if(bState!=""){
         $("select#busAddState").find("option#"+bState).attr("selected", true); 
    }else{
        $("select#busAddState").find("option#default_bstate").attr("selected", true); 
    }
    if(callF!=""){
        $("select#callFreq").find("option#"+callF).attr("selected", true); 
    }
    if(cargoF!=""){
         $("select#cargoFreq").find("option#"+cargoF).attr("selected", true); 
    }
    if(remitF!=""){
         $("select#remitReq").find("option#"+remitF).attr("selected", true); 
    }
   
   
   var sofs = sof.split(',');
   if(sofs!=""){
     $("select#srcOfFunds option").removeAttr("selected");
    for(var i=0;i<sofs.length;i++){
        $("select#srcOfFunds").find("option#"+sofs[i]).attr("selected", true);  
    }
  }

   var emps = emp.split(',');
   if(emps!=""){
     $("select#employment option").removeAttr("selected");
    for(var a=0;a<emps.length;a++){
        $("select#employment").find("option#"+emps[a]).attr("selected", true);    
    }
  }
   var mors = mor.split(',');
   if(mors!=""){
    $("select#modeOfRemit option").removeAttr("selected");
   for(var b=0;b<mors.length;b++){
       $("select#modeOfRemit").find("option#"+mors[b]).attr("selected", true);    
   }
  }
   var mocs= moc.split(',');
   if(mocs!=""){
    $("select#modeOfCall option").removeAttr("selected");
    for(var c=0;c<mocs.length;c++){
        $("select#modeOfCall").find("option#"+mocs[c]).attr("selected", true);    
    }
 }
   var mocoms = mocom.split(',');
   if(mocoms!=""){
     $("select#prefModeOfComm option").removeAttr("selected");
    for(var d=0;d<mocoms.length;d++){
        $("select#prefModeOfComm").find("option#"+mocoms[d]).attr("selected", true);    
    }
  }
   var prefDays = prefDay.split(',');
   if(prefDays!=""){
   $("select#prefCallDay option").removeAttr("selected");
    for(var e=0;e<prefDays.length;e++){
        $("select#prefCallDay").find("option#"+prefDays[e]).attr("selected", true);    
    }
   }
   var prefTimes= prefTime.split(',');
   if(prefTimes!=""){
    $("select#prefCallTime option").removeAttr("selected");
    for(var f=0;f<prefTimes.length;f++){
       $("select#prefCallTime").find("option#"+prefTimes[f]).attr("selected", true);    
   }
 }
   
   var atcs= allowContact.split(',');
   if(atcs!=""){
   $("#tabs :input").prop("checked",false);
   for(var g=0;g<atcs.length;g++){
       var elem = "#chk-"+atcs[g];
       $(elem).prop("checked",true);    
   }
 }
  
   //gender
   var gender = "#radio-"+data.Gender;
   if(gender!=""){
     $(gender).prop("checked",true);
   }
  if(notes!=""){
     $("#notes").val(notes);  
  }
}


 //set dialog box message
function getDialogMessage(mode){
    var pmode = parseInt(mode);
    var message="";
    switch (pmode){
        case 0:
            message="Are you sure you want to save this customer?";
            break;
        case 1:
            message="Are you sure you want to save the changes made on this customer?";
            break;
        case 2:
            message="Are you sure you want to save the changes made on this customer?";
            break;
        case 3:
            message="Are you sure you want to save the changes made on this customer?";
            break;
            
    }
    
    $("#dialog").html("<p>"+message+"</p>");
    
}

function getCustomerData(){
    var id=$("#custId").val();
    var customerData=null;
    $.ajax({
            url:"/Customer/Services/CustomerService/getcustomer/"+id,
            async:false,
            cache:false,
            dataType:'json',
            success: function(data){
                 customerData=data[0];
                 
            }});
          
     return customerData;       
}

function refreshCustomerData(){
    var data = getCustomerData();
    setCustomerData(data);
}

function editModeOn(){
    $('#tabs :input').attr('disabled',true);
    $('#addCustomer').val("EDIT");
    $('#applyCC').val('APPLY FOR CASH CARD');
    $('#cancel').attr('disabled',true);
     
}

function cancelModeOn(){
    $('#cancel').removeAttr('disabled');
}
</script>

  
<form  method="post" id="custForm" >
    <div id="message"></div>
    <input type="hidden" id="saveOption" name="saveOption"/>
    <input type="hidden" id="hasDup" name="hasDup" value="@customer.HasDuplicate"/>
    <input type="hidden" id="rByid" name="rByid"/>
    <input type="hidden" id="changeFormVal" name="changeFormVal"/>
    
    
    <div id="dialog" title="Save Customer">
        <p>Are you sure you want to save this customer?</p>
    </div>
     <h2><label id="lblBigCustID">@customer.CustomerID</label> <br/>
      <span id="lblCustomerHeader">Customer:@customer.FName @customer.LName</span></h2><br/>

    <div id="tabs">
    <ul>
        <li ><a href="#tab1">Classification</a></li>
        <li ><a href="#tab2">Lead Source</a></li>
        <li ><a href="#tab3">Personal Information</a></li>
        <li ><a href="#tab4">Work and Finances</a></li>
        <li ><a href="#tab5">Additional Information</a></li>
        <li ><a href="#tab6">Contact Permission</a></li>
        <li><a href="#tab7">Notes</a></li>
        
    </ul> 
   <input type="hidden" name="custId" id="custId" value="@customer.CustomerID"/>   
    <fieldset class="customer">    
    <div id="tab1">
        
      <p>
        <label for="lblCustID">CUSTOMER ID:</label>
        <label id="lblCustID">@customer.CustomerID</label>
      </p>
      <p>  
        <label for="custClass">CLASSIFICATION:</label>
        <select id="custClass" name="custClass" >
            @foreach(var r in Page.CustClass){
                 if(r.RefID.Equals(@customer.CustomerClassification)){
                   <option id="@r.RefDesc" value="@r.RefID" selected="selected">@r.RefDesc</option>
                }else{
                    <option id="@r.RefDesc" value="@r.RefID" >@r.RefDesc</option>
                }
              
            }
        </select>
        </p>
        
        <p><label for="custStatus">CUSTOMER STATUS:</label>
           <select name="custStatus" id="custStatus">
            @foreach(var r in Page.CustStatus){
                if(r.RefID.Equals(@customer.CustomerStatus)){
                   <option id="@r.RefDesc" value="@r.RefID" selected="selected">@r.RefDesc</option>    
                }else{
                    <option id="@r.RefDesc" value="@r.RefID">@r.RefDesc</option>
                }
                
            }
        </select>  
        </p>
        
    </div> <!--end of tab-->
   
     <div id="tab2">
        <table style="border:0;margin:0px;font-size:1.2em">
            <tr>
                <td>
        <p><label for="region">REGION:</label></p>
        <p>
        <select name="region" id="region">
            @foreach(var r in Page.Region){
                if(r.RefID.Equals(@customer.Region)){
                  <option id="@r.RefDesc" value="@r.RefID" selected="selected">@r.RefDesc</option>    
                }else{
                   <option id="@r.RefDesc" value="@r.RefID">@r.RefDesc</option>  
                }
                
            }
        </select>
            </p>
                    </td>
                <td>
        <p><label for="solicitor">SOLICITOR:</label></p>
        <p>
        <select name="solicitor" id="solicitor">
            <option id="default_solicitor"></option>
            @foreach(var r in Page.Solicitor){
                if(r.RefID.Equals(@customer.Solicitor)){
                      <option id="@r.RefID" value="@r.RefID" selected="selected">@r.RefDesc</option>
                }else{
                      <option id="@r.RefID" value="@r.RefID">@r.RefDesc</option>
                }
              
            }
        </select>
        </p>    
                    </td>
                <td>
        <p><label for="campaign">CAMPAIGN:</label></p>
        <p><select name="campaign" id="campaign">
            <option id="default_campaign"></option>
            @foreach(var r in Page.Campaign){
                if(r.RefID.Equals(@customer.Campaign)){
                    <option id="@r.RefID" value="@r.RefID" selected="selected">@r.RefDesc</option>
                }else{
                    <option id="@r.RefID" value="@r.RefID">@r.RefDesc</option>
                }
                
            }
        </select>
            </p>
                    </td>
                <td>
        <p> <label for="refBy">REFERRED BY:</label></p>
            <p><div id="rBylabel"></div>
            <input id="rBy" name="rBy" value="@custRefBy"/>
       <!-- <select name="refBy" id="refBy">
            <option></option>
            @foreach(var r in Page.RefBy){
               if(r.CustomerID.Equals(@customer.ReferredBy)){
                  <option value="@r.CustomerID" selected="selected">@r.FName @r.LName</option>    
            } else{
                   <option value="@r.CustomerID">@r.FName @r.LName</option>
            }
            
            }
        </select>-->
         </p>   
                    </td>
                <td>
        <p><label for="rel2ref">RELATIONSHIP TO REFERROR:</label></p>
        <p><select name="rel2ref" id="rel2ref">
            <option id="default_r2r"></option>
            @foreach(var r in Page.Rel2Ref){
                if(r.RefID.Equals(@customer.RelationshipToReferror)){
                      <option id="@r.RefID" value="@r.RefID" selected="selected">@r.RefDesc</option>
                }else{
                     <option  id="@r.RefID" value="@r.RefID">@r.RefDesc</option> 
                }
                
            }
        </select>
            </p>
            </td>
                </tr>
            </table>
        </div>
  <!----- Personal Information tab---------------------------------------------------------------------->   
    <div id="tab3" style="height:330px;padding:0;margin:0;">
        <div id="personal_accordion"><!----start of accordion----->
        <h3 id="tab3h3-1"><a href="#">Personal Details</a></h3>
        <div>
        <div style="float:left;margin:0 1.0em 0 0;">    
        <p><label for="country">COUNTRY:</label>
            <select name="country" id="country">
             @foreach(var c in countryLkUp){
                if(c.RefID.Equals(@customer.CurrMailCountry)){
                  <option id="@c.RefID" value="@c.RefID" selected="selected">@c.RefDesc</option>    
                }else{
                    <option id="@c.RefID" value="@c.RefID">@c.RefDesc</option>
                }
              }
        </select>
        </p>    
        <p>
      <label for="monArr">MONTH &amp; YEAR ARRIVED </label>
        <select name="monArr" id="monArr">
            <option id="ma"></option>
            @foreach(var r in Page.Month){
                if(r.RefID.Equals(@customer.MonthArrived)){
                     <option id="@r.RefID" value="@r.RefID" selected="selected">@r.RefDesc</option>
                }else{
                     <option id="@r.RefID" value="@r.RefID">@r.RefDesc</option>
                }
               
            }
        </select>
        
        
        <select name="yrArr" id="yrArr">
            <option id="ya"></option>
            @foreach(var r in Page.Year){
                if(r.RefID.Equals(@customer.YearArrived)){
                     <option id="@r.RefID" value="@r.RefID" selected="selected">@r.RefDesc</option>
            
                }else{
                     <option id="@r.RefID" value="@r.RefID">@r.RefDesc</option>
                }
              } 
        </select>
        </p>    
        <p>
        <label for="fname">*FIRST NAME:</label>
        <input type="text" name="fname" id="fname" value="@customer.FName"  size="20" class="TestClass"/>
         <label id="fname_error" class="validation-error">This field is required </label>
        </p>
        <p>
         <label for="mname">*MIDDLE NAME:</label>
        <input type="text" name="mname" id="mname" value="@customer.MName"   size="20"/>
        <label id="mname_error" class="validation-error">This field is required </label>
        </p>
        <p>
         <label for="lname">*LAST NAME:</label>
        <input type="text" name="lname" id="lname" value="@customer.LName"  size="20"/>
        <label for="lname" id="lname_error" class="validation-error">This field is required </label>      
      </p>
       
        <p>
        <label>*GENDER:</label>
             <label for="gender" id="gender_error" class="validation-error">This field is required </label>  
            <div id="gender_container">      
            <input type="radio" id="radio-m" name="gender" value="m" />Male
            <input type="radio" id="radio-f" name="gender" value="f" />Female
            </div>
        
         </p>
            
         <p>
        <label for="datepicker">BIRTHDAY:</label>
        <input type="text" id="bdate" value="@bDate" name="bdate"/>
        <label for="bdate" id="bdate_error" class="validation-error">This field is required </label>       
        </p>
        </div>
        <div style="float:left;margin:0">    
        <p>
        <label for="nationality">NATIONALITY:</label>
        <select name="nationality" id="nationality">
            @foreach(var r in Page.Nationality){
               if(r.RefID.Equals(@customer.Nationality)){
                <option id="@r.RefDesc" value="@r.RefID" selected="selected">@r.RefDesc</option>
                }else{
                    <option id="@r.RefDesc" value="@r.RefID">@r.RefDesc</option>
                } 
               
            }
        </select>    
        </p>
        <p>
        <label for="pob">PLACE OF BIRTH:</label>
        <input type="text" name="pob" id="pob" value="@customer.PlaceOfBirth"/> 
        <label for="pob" id="pob_error" class="validation-error">This field is required </label>    
        </p>
        <p>
        <label for="mMName">MOTHER'S MAIDEN NAME:</label>
        <input type="text" id="mMName" name="mMName" value="@customer.MotherMName"/>
        </p>
        <p>
        <label>CIVIL STATUS:</label>
        <select name="civilStatus" id="civilStatus">
            <option id="default_cs" value="default"> </option>
            @foreach(var r in Page.CivilStatus){
                if(r.RefID.Equals(@customer.CivilStatus)){
                    <option id="@r.RefID" value="@r.RefID" selected="selected">@r.RefDesc</option>
                }else{
                    <option id="@r.RefID" value="@r.RefID">@r.RefDesc</option>
                }
                
            }
        </select>    
        </p>
        <p>
        <label for="idType">ID Type:</label>
        <select name="idType" id="idType">
            <option id="default_idType" value="default"></option>
            @foreach(var r in Page.IDType){
                if(r.RefID.Equals(@customer.IDType)){
                     <option id="@r.RefID" value="@r.RefID" selected="selected">@r.RefDesc</option>
                }else{
                     <option id="@r.RefID" value="@r.RefID">@r.RefDesc</option>
                }
               
            }
        </select>    
        </p>
        <p>
        <label for="idNo">ID NUMBER:</label>
        <input type="text" id="idNo" name="idNo" value="@customer.IDNumber"/>
        <label for="idNo" id="idNo_error" class="validation-error">This field is required </label>    
        </p>
         </div>   
        </div><!-----end of Personal Details section---->
            
        <h3 id="tab3h3-2"><a href="#">Contact Details</a></h3>
        <div>  
        <div id="phone_countainer">     
        <p>
        <label>*MOBILE NO:</label>
         <input type="text" style="width:100px" name="mobileCC" id="mobileCC" value="@mobileCC"/>-<input type="text"  style="width:100px"  id="mobileAC" name="mobileAC" value="@mobileAC"/>-<input type="text" name="mobilePNo" id="mobileNo" value="@mobileNo"/>    
         (Country Code + Area Code + Phone No)
        </p>
        <p>
        <label>*LANDLINE NO:</label>
        <input type="text"  style="width:100px" name="landLineCC" id="landLineCC" value="@landLineCC"/>-<input type="text"  style="width:100px" id="landLineAC" name="landLineAC" value="@landLineAC"/>-<input type="text" name="landLinePNo" id="landLineNo" value="@landLineNo"/>
         (Country Code + Area Code + Phone No.)
         <label id="phoneNo_error" class="validation-error">at least one phone number is required </label>   
        </p>
        </div>    
        <div >  
        <p>
        <label for="email">EMAIL ADDRESS:</label>
        <input type="text" id="email" name="email" value="@customer.Email" class="required email"/>
        </p>
         </div>     
        </div>
       
        <h3 id="tab3h3-3"><a href="#">Address</a></h3> 
        <div>    
           
        <p>
        <label>CURRENT MAILING ADDRESS</label>
         </p>
        
        <p>
        *<input type="text"  name="currMailAdd1" style="width:500px" size="100" id="currMailAdd1" value="@currMailAdd1"/>(Address1: Flat No., Room No., Building Name, Villa No.)
        <label id="currMailAdd1_error" class="validation-error">this field is required </label>   
        </p>
        <p>
        *<input type="text" name="currMailAdd2" style="width:500px" size="100" id="currMailAdd2" value="@currMailAdd2"/>(Address2: Street Name)
        <label id="currMailAdd2_error" class="validation-error">this field is required </label>   
       
        </p>
        <div style="float:left;margin:0 1em 0 0">    
        <p> 
        *<input type="text" name="currMailCity" id="currMailCity" value="@customer.CurrMailCity"/>(City)
         <label id="currMailCity_error" class="validation-error">this field is required </label>   
           
        </p>
        </div>    
         <div style="float:left">   
         <p><label for="currMailCountry">*(COUNTRY)</label></p>
         <p>
         <select name="currMailCountry" id="currMailCountry">
            @foreach(var country in countryLkUp){
                if(country.RefID.Equals(@customer.CurrMailCountry)){
                  <option id="@country.RefID" value="@country.RefID" selected="selected">@country.RefDesc</option>    
                }else{
                    <option id="@country.RefID" value="@country.RefID">@country.RefDesc</option>
                }
            }
            
        </select>   
           <label id="currMailCountry_error" class="validation-error">this field is required </label>   
         
        </p>
         </div>
         <div style="float:left">       
        <p><label for="currMailState">*(STATE)</label></p>
        <p>    
        <select name="currMailState" id="currMailState">
            <option id="default_cstate"></option>
           @foreach(var s in stateLkUp){
                if(s.RefID.Equals(@customer.CurrMailState)){
                  <option id="@s.RefID" value="@s.RefID" selected="selected">@s.RefDesc</option>    
                }else{
                    <option id="@s.RefID" value="@s.RefID">@s.RefDesc</option>
                }
              }  
          }
        </select>
        </p>
        </div>    
        <div style="float:left">   
        <p>
        <label for="currMailZip">ZIP CODE:</label></p>
         <p>   <input type="text" style="width:100px" id="currMailZip" value="@customer.CurrMailZip" name="currMailZip"/>
        </p>
        </div>    
        <p>
        <label for="chkSameAdd">PERMANENT  ADDRESS</label>  <input type="checkbox" id="chkSameAdd" name="sameAsMailAdd"/> (Same as mail address)
        </p>
        <p>
        <input type="text" id="permAdd1"  style="width:500px" size="100" name="permAdd1" value="@permAdd1"/>(Address1: Flat No., Room No., Building Name, Villa No.)
        </p>
        <p>
        <input type="text" id="permAdd2" style="width:500px" size="100" name="permAdd2" value="@permAdd2"/>(Address2: Street Name)
        </p>
        <div style="float:left;margin:0 1em 0 0">        
        <p>
        <input type="text" id="permAddCity" name="permAddCity" value="@customer.PermAddCity"/>(City)
        </p>
        </div>    
        <div style="float:left">     
        <p><label for="permAddCountry">(COUNTRY)</label></p>
        <p>    
        <select name="permAddCountry" id="permAddCountry">
           @foreach(var pc in countryLkUp){
                if(pc.RefID.Equals(@customer.PermAddCountry)){
                  <option id="@pc.RefID" value="@pc.RefID" selected="selected">@pc.RefDesc</option>    
                }else{
                    <option id="@pc.RefID" value="@pc.RefID">@pc.RefDesc</option>
                }
            }
        </select></p></div>
        <div style="float:left;">    
        <p><label for="permAddState">(STATE)</label></p>
        <p><select name="permAddState" id="permAddState">
          <option id="default_pstate"></option>  
          @foreach(var s in stateLkUp){
                if(s.RefID.Equals(@customer.PermAddState)){
                  <option id="@s.RefID" value="@s.RefID" selected="selected">@s.RefDesc</option>    
                }else{
                    <option id="@s.RefID" value="@s.RefID">@s.RefDesc</option>
                }
            }
        </select>     
        </p> 
        </div>
        <div style="float:left">    
       <p><label for="permAddZip">ZIP CODE:</p>
            <p></label><input type="text" style="width:100px" value="@customer.PermAddZip" id="permAddZip" name="permAddZip"/>
       </p>
        </div>    
       </div>     
      </div><!----end of accordion--->
     </div>
   <!--------------------------------End of Personal Information Tab-------------------------------------------------------->

        <div id="tab4" style="height:300px;padding:0;margin:0">
          <div id="wnf_accordion"><!----start of accordion----->
           <h3 id="tab4h3-1"><a href="#">Work And Finance Details</a></h3>
          <div>
          
          <div style="float:left;margin:0 1em 0 0">
          <p> <label for="srcOfFunds">SOURCE OF FUNDS:</label></p>
                    <p>
            <select name="srcOfFunds" id="srcOfFunds" multiple="multiple" size="10">
           @foreach(var r in Page.SrcOfFund){
              <option id="@r.RefID" value="@r.RefID">@r.RefDesc</option>
               
            }
           </select> 
         </p>
          </div>
          <div style="float:left;margin:0 1em 0 0">  
          
         <p> <label for="employment">EMPLOYMENT:</label></p>
            <p>
            <select name="employment" id="employment" multiple="multiple" size="10">
            <option id="default_emp"></option>    
            @foreach(var r in Page.EmpType){
                if(r.RefID.Equals(@customer.Employment)){
                  <option id="@r.RefID"  value="@r.RefID" selected="selected">@r.RefDesc</option>   
                }else{
                    <option  id="@r.RefID"  value="@r.RefID">@r.RefDesc</option>
                }
                
            }
           </select> 
        </p>
          </div>  
          <div style="float:left;border:0;margin:1em;>  
            <p>
            <label for="desigRank">DESIGNATION / RANK:</label></p>
            <p>
             <select name="desigRank" id="desigRank">
                <option></option>
            @foreach(var r in Page.DesigRank){
                if(r.RefID.Equals(@customer.Designation)){
                    <option id="@r.RefID" value="@r.RefID" selected="selected">@r.RefDesc</option>
                }else{
                   <option id="@r.RefID" value="@r.RefID">@r.RefDesc</option> 
                }
                
            }
            </select>    
            </p>
           <p>
            <label for="busName">EMPLOYER / BUSINESS NAME:</label></p>
            <p>
            <input type="text" id="busName" class="required" name="busName" value="@customer.Employer"/>
            <label for="busName" id="busName_error" class="validation-error">This field is required </label>
            
        </p>
            <p><label for="natureOfWork">NATURE OF WORK / BUSINESS:</label></p>
            <p>
            <select name="natureOfWork" id="natureOfWork">
                <option></option>
            @foreach(var r in Page.NatureOfWork){
                if(r.RefID.Equals(@customer.NatureOfWork)){
                    <option id="@r.RefID" value="@r.RefID" selected="selected">@r.RefDesc</option>
                }else{
                    <option id="@r.RefID" value="@r.RefID">@r.RefDesc</option>
                }
                
            }
            </select>     
            </p>
            </div>
            </div>
            <h3 id="tab4h3-4"><a href="#">Work Address</a></h3>
            <div>
           <div style="margin:0 1em 0 0"> 
           <p><label>LANDLINE NO:</label></p>
            <p>
          
            <input type="text"  style="width:100px" name="busPhoneCC" id="busPhoneCC" value="@workPCC"/>-<input type="text"  style="width:100px" id="busPhoneAC" name="busPhoneAC" value="@workPAC"/>-<input type="text" id="busPhoneNo" name="busPhoneNo" value="@workPNo"/>(Country Code + Area Code + Phone No.)
            
        </p>
            <p>
            <label>BUSINESS  ADDRESS</label>
              </p>
            <p>
            <input type="text" size="100" name="busAdd1" style="width:500px" value="@busAdd1"/>(Address1: Flat No., Room No., Building Name, Villa No.)
            </p>
            <p>
              <input type="text" size="100" name="busAdd2" style="width:500px" value="@busAdd2"/>(Address2: Street Name)
                
            </p>
            <div style="float:left;margin:0 1em 0 0">
            <p>
            <input type="text" name="busAddCity" value="@customer.BusAddCity"/>(City)
            </p>
            </div>    
            </div>
            <div style="float:left">
            <p><label for="busAddCountry">(COUNTRY)</label></p>
       <p>
         <select name="busAddCountry" id="busAddCountry">
            <option id="default_bcountry"></option>
           @foreach(var bc in countryLkUp){
                if(bc.RefID.Equals(@customer.BusAddCountry)){
                  <option value="@bc.RefID" selected="selected">@bc.RefDesc</option>    
                }else{
                    <option value="@bc.RefID">@bc.RefDesc</option>
                }
            }
        </select>       
            </p>
            </div>
            <div style="float:left">
            <p> <label for="busAddState">(STATE)</label></p>
            <p>
        <select name="busAddState" id="busAddState">
            <option id="default_bstate"></option>
            @foreach(var s in stateLkUp){
                if(s.RefID.Equals(@customer.BusAddState)){
                  <option value="@s.RefID" selected="selected">@s.RefDesc</option>    
                }else{
                    <option value="@s.RefID">@s.RefDesc</option>
                }
            }
        </select>        
            </p>
           </div>
           <div style="float:left">
     
           <p><label for="busAddZip">ZIP CODE:</label></p>
            <p><input type="text" style="width:100px" id="busAddZip" value="@customer.BusAddZip" name="busAddZip"/>
            
        </p>
            </div>
          </div>  
          </div>  
        </div>
        
        <div id="tab5">
           <table style="border:0;margin:0px;font-size:1.2em">
            <tr>
                 <td style="vertical-align:top">
            <p><label for="modeOfRemit">MODE OF REMITTANCE:</label></p>
            <p>        
         <select name="modeOfRemit" id="modeOfRemit" size="10" multiple="multiple">
            @foreach(var r in Page.ModeOfRemit){
                if(r.RefID.Equals(@customer.ModeOfRemit)){
                     <option id="@r.RefID" value="@r.RefID">@r.RefDesc</option>
                }else{
                     <option id="@r.RefID" value="@r.RefID">@r.RefDesc</option>
                }
               
            }
        </select>          
            </p>
                    </td>
                <td style="vertical-align:top">
          <p><label for="remitReq">REMITTANCE FREQUENCY:</label></p>
                    <p>
         <select name="remitReq" id="remitReq">
            <option></option>
            @foreach(var r in Page.RemitFreq){
                if(r.RefID.Equals(@customer.RemitFrequency)){
                    <option id="@r.RefID" value="@r.RefID" selected="selected">@r.RefDesc</option>
                }else{
                    <option id="@r.RefID" value="@r.RefID">@r.RefDesc</option>
                }
                
            }
        </select>  
        </p>    
         </td>
                <td style="vertical-align:top">
      <p><label for="callFreq">CALL FREQUENCY:</label></p>
                    <p>
         <select name="callFreq" id="callFreq">
            <option></option>
            @foreach(var r in Page.CallFreq){
                if(r.RefID.Equals(@customer.CallFrequency)){
                     <option id="@r.RefID" value="@r.RefID" selected="selected">@r.RefDesc</option>
                }else{
                     <option id="@r.RefID" value="@r.RefID">@r.RefDesc</option>
                }
               
            }
        </select>
              
    </p>
                    </td>
         <td style="vertical-align:top"> 
             <p><label for="modeOfCall">MODE OF CALL:</label></p>
            <p>
         <select name="modeOfCall" id="modeOfCall" size="10"  multiple="multiple">
            @foreach(var r in Page.ModeOfCall){
                if(r.RefID.Equals(@customer.ModeOfCall)){
                    <option id="@r.RefID" value="@r.RefID">@r.RefDesc</option>
                }else{
                    <option id="@r.RefID" value="@r.RefID">@r.RefDesc</option>
                }
            }
        </select>
            
        </p>   
            </td>
                <td style="vertical-align:top">
            <p> <label for="cargoFreq">CARGO FREQUENCY:</label></p>
            <p>
         <select name="cargoFreq" id="cargoFreq">
            <option></option>
            @foreach(var r in Page.CargoFreq){
                if(r.RefID.Equals(@customer.CargoFrequency)){
                     <option id="@r.RefID" value="@r.RefID" selected="selected">@r.RefDesc</option>
                }else{
                    <option id="@r.RefID" value="@r.RefID">@r.RefDesc</option>
                }
               
            }
        </select>    
               
            </p>
       </td>
                </tr>
                </table>
        </div>
        
        <div id="tab6">
            <table style="border:0;margin:0px;font-size:1.2em">
            <tr>
                 <td>
            <p>
            <label>ALLOW TO BE CONTACTED VIA:</label></p>
             <p>       
            @foreach(var atc in Page.ModeOfCall){
               <input type="checkbox" id="chk-@atc.RefID" name="allowContact" value="@atc.RefID"/>@atc.RefDesc<br/>
                
            }    
            </p>
                    </td>
                <td>
            
            <p><label for="prefModeOfComm">PREFERRED MODE OF COMMUNICATION</label></p>
            <p>        
                
            <select name="prefModeOfComm" id="prefModeOfComm" size="5" multiple="multiple">
            @foreach(var r in Page.PrefModeOfComm){
                if(r.RefID.Equals(@customer.PrefModeOfComm)){
                     <option id="@r.RefID" value="@r.RefID" selected="selected">@r.RefDesc</option>
                }else{
                     <option id="@r.RefID" value="@r.RefID">@r.RefDesc</option>
                }
                
               
            }
        </select>
      
            </p>
            </td>
            <td>        
            <p>
            <label for="prefCallDay">PREFERRED DAY TO BE CALLED</label></p>
                <p>
            <select name="prefCallDay" id="prefCallDay" size="5" multiple="multiple">
            @foreach(var r in Page.PrefDayOfCall){
                if(r.RefID.Equals(@customer.PreffCallDay)){
                     <option id="@r.RefID" value="@r.RefID" selected="selected">@r.RefDesc</option>
                }else{
                     <option id="@r.RefID" value="@r.RefID">@r.RefDesc</option>
                }
                
               
            }
        </select>    
            </p>
                </td>
                    <td>
            <p>
            <label for="prefCallTime">PREFERRED TIME TO BE CALLED</label></p>
            <p>            
            <select name="prefCallTime" id="prefCallTime" size="5" multiple="multiple">
            @foreach(var r in Page.PrefTimeOfCall){
                if(r.RefID.Equals(@customer.PrefCallTime)){
                     <option id="@r.RefID" value="@r.RefID" selected="selected">@r.RefDesc</option>
                }else{
                     <option id="@r.RefID" value="@r.RefID">@r.RefDesc</option>
                }
               
            }
        </select>    
            </p>
            </td>
                    </tr>
                </table>
            </div>
            
         <div id="tab7">
            <p>
            <label for="notes">REMARKS:</label><textarea id="notes" name="notes" rows="10" cols="50" >@customer.Notes</textarea>
                
            </p>
            </div>
            </fieldset>
     </div>
    
    <br/>
     <div id="buttons" align="center">
       <input type="button" id="addCustomer"  value="SAVE"/>
       <input type="button" id="applyCC"  value="SAVE AND APPLY FOR CASH CARD"/>
       <input type="button" id="cancel"  value="CANCEL"/>
        
     
            
        </div>
 
     </form>
 <div id="cash_card_form" method="post" title="Cash Card Details">
     <!--div for cash card form-->
     <form id="ccForm">
        <input type="hidden" name="cID" id="cID" value="@customer.CustomerID"/> 
        <input type="hidden" name="ccId" id="ccId" value=""/>
        <input type="hidden" name="changeCCData" id="changeCCData"/>
        <fieldset  style="font-size:1.1em">
         <legend>Customer Details</legend>
         <p>
        <div class="validateCC">    
        <label for="cc_cstatus">*CIVIL STATUS:</label>
        <select name="cc_civilStatus" id="cc_cstatus">
            <option id="default_cs" value="default"></option>
            @foreach(var r in Page.CivilStatus){
                if(r.RefID.Equals(@customer.CivilStatus)){
                    <option id="@r.RefID" value="@r.RefID" selected="selected">@r.RefDesc</option>
                }else{
                    <option id="@r.RefID" value="@r.RefID">@r.RefDesc</option>
                }
                
            }
        </select>
         </div>
          <div class="validateCC">    
           <label for="cc_cstatus" id="cc_cstatus_error" class="validation-error">This field is required </label>   
          </div>  
        </p>    
        <p>
        <div class="validateCC">    
        <label for="ccidType">ID TYPE:</label>
        <select name="ccidType" id="ccidType">
            <option id="default_idType" value="default"></option>
            @foreach(var r in Page.IDType){
                if(r.RefID.Equals(@customer.IDType)){
                     <option id="@r.RefID" value="@r.RefID" selected="selected">@r.RefDesc</option>
                }else{
                     <option id="@r.RefID" value="@r.RefID">@r.RefDesc</option>
                }
               
            }
        </select>
         </div>
          <div class="validateCC">    
         <label for="ccidType" id="ccidType_error" class="validation-error">This field is required </label>
          </div>  
        </p>   
         <p>
         <div class="validateCC">    
        <label for="ccidNo">ID NUMBER:</label>
        <input type="text" id="ccidNo" name="ccidNo" value="@customer.IDNumber"/>
        </div>
         <div class="validateCC">    
         <label for="ccidNo" id="ccidNo_error" class="validation-error">This field is required </label> 
         </div>   
        </p>
        <p>
           <div class="validateCC">    
          <label for="datepicker">*BIRTHDAY:</label>
          <input type="text" id="ccbdate" value="@bDate" name="ccbdate"/>
          </div>
           <div class="validateCC">    
          <label for="bdate" id="ccbdate_error" class="validation-error">This field is required </label>    
          <label for="bdate" id="ccbdate_age_error" class="validation-error">age should be 16 years and above</label>    
           </div> 
        </p>
        <p>
           <div class="validateCC">    
          <label for="ccpob">*PLACE OF BIRTH:</label>
          <input type="text" id="ccpob" value="@customer.PlaceOfBirth" name="ccpob"/>
          </div>
           <div class="validateCC">    
          <label for="ccpob" id="ccpob_error" class="validation-error">This field is required </label>  
           </div> 
        </p>
        <p>
             <div class="validateCC">    
            <label for="srcOfFunds">*SOURCE OF FUNDS:</label>
            <select name="ccsrcOfFunds" id="ccsrcOfFunds" multiple="multiple" size="10">
           @foreach(var r in Page.SrcOfFund){
              <option id="@r.RefID" value="@r.RefID">@r.RefDesc</option>
               
            }
           </select> 
           </div>
            <div class="validateCC">    
           <label for="ccsrcOfFunds" id="ccsrcOfFunds_error" class="validation-error">This field is required </label>    
            </div>    
         </p>
          <p>
             <div class="validateCC">    
            <label for="ccbusName">EMPLOYER / BUSINESS:</label>
            <input type="text" id="ccbusName"  name="ccbusName" value="@customer.Employer"/>
            </div>
             <div class="validateCC">    
            <label for="ccbusName" id="ccbusName_error" class="validation-error">This field is required </label>
             </div>   
            
        </p>
           <p>
             <div class="validateCC">    
            <label for="ccnatureOfWork">NATURE OF WORK / BUSINESS NAME:</label>
            <select name="ccnatureOfWork" id="ccnatureOfWork">
             <option id="default_ccnow"></option>
            @foreach(var r in Page.NatureOfWork){
                if(r.RefID.Equals(@customer.NatureOfWork)){
                    <option id="@r.RefID" value="@r.RefID" selected="selected">@r.RefDesc</option>
                }else{
                    <option id="@r.RefID" value="@r.RefID">@r.RefDesc</option>
                }
                
            }
            </select>     
            </div>
             <div class="validateCC">    
              <label for="ccnatureOfWork" id="ccnatureOfWork_error" class="validation-error">This field is required </label>    
             </div>   
            </p>  
            
        </fieldset>  
        <fieldset  style="font-size:1.1em">
            <legend>Cash Card Details</legend>
       
        <p>
         <div class="validateCC">    
        <label for="lblCCID">CASH CARD APPLICATION NO:</label> <label id="lblCCID"></label>
         </div>   
        </p>
        <p>
         <div class="validateCC">    
        <label for="cashCardStatus">CASH CARD STATUS:</label> <select name="cashCardStatus" id="cashCardStatus">
            @foreach(var cStatus in ccStatus){
                if (cStatus.RefID.Equals("PEN")){
                    <option id="@cStatus.RefDesc" value=@cStatus.RefID selected="selected">@cStatus.RefDesc</option>}
                else{
                    <option id="@cStatus.RefDesc" value=@cStatus.RefID>@cStatus.RefDesc</option>}
            }            
        </select>
        </div>    
            
        </p>
        <p>
         <div class="validateCC">    
        <label for="appdate">*APPLICATION DATE:</label>
        <input type="text" name="appDate"  id="appdate"/>
         </div>
          <div class="validateCC">    
        <label for="appdate" id="appdate_error" class="validation-error">This field is required </label> 
          </div>  
        </p>
        <p>
         <div class="validateCC">    
        <label for="ccsdate">*CASH CARD STATUS DATE:</label>
        <input type="Text" name="ccStatusDate" value="" id="ccsdate"/>
        </div>    
         <div class="validateCC">    
        <label for="ccsdate" id="ccsdate_error" class="validation-error">This field is required </label> 
         </div>     
        </p>
        <p>
         <div class="validateCC">    
        <label for="docStatus">DOCUMENT STATUS:</label> <select name="docStatus" id="docStatus">
            @foreach(var cDocStatus in ccDocStatus){
                if (cDocStatus.RefID.Equals("INC")){
                <option id="@cDocStatus.RefDesc" value=@cDocStatus.RefID selected="selected">@cDocStatus.RefDesc</option>}
                else{
                    <option id="@cDocStatus.RefDesc" value=@cDocStatus.RefID>@cDocStatus.RefDesc</option>}
            }            
        </select>    
        </p>
        </div>    
          <p>
         <div class="validateCC">    
        <label for="remarks">REMARKS:</label> <textarea style="font-size:1.2em" name="remarks" id="remarks" cols="50" rows="10"></textarea>
         </div>
          <div class="validateCC">    
         <label for="remarks" id="remarks_error" class="validation-error">This field is required </label>      
         </div>
        </p>    
        <p>
         <div class="validateCC">    
        <label for="ccno">CASH CARD NO:</label> <input type="text" name="txtCcNo" id="ccno"></input>
        </div>    
        </p>
        <p>
         <div class="validateCC">    
        <label for="cardType">CASH CARD TYPE:</label> <select name="cardType" id="cardType">
            @foreach(var cType in ccType){
                if (cType.RefID.Equals("PER")){
                    <option id="@cType.RefDesc" value=@cType.RefID selected="selected">@cType.RefDesc</option>}
                else{
                    <option id="@cType.RefDesc" value=@cType.RefID>@cType.RefDesc</option>}
            }            
        </select>
         </div>  
        </p>
        <p>
         <div class="validateCC">    
        <label for="partnerBank">PARTNER BANK:</label> <select name="partnerBnk" id="partnerBank">
            @foreach(var cPartenerBnk in ccPartnerBank){
                if (cPartenerBnk.RefID.Equals("CT")){
                    <option id="@cPartenerBnk.RefID" value=@cPartenerBnk.RefID selected="selected">@cPartenerBnk.RefDesc</option>}
                else{
                    <option id="@cPartenerBnk.RefID" value=@cPartenerBnk.RefID>@cPartenerBnk.RefDesc</option>}
            }            
        </select> 
        </div>    
        </p>
        <!--<p>
        <label for="sdate">STATUS DATE:</label>
        <input type="Text" name="txtStatusDate" value="" id="sdate">
         <label for="sdate" id="sdate_error" class="validation-error">This field is required </label>      
        </p>-->
        <p>
         <div class="validateCC">    
        <label for="cardName">NAME ON CARD: </label><input type="text" name="txtName" id="cardName" value="@customer.FName + @customer.LName"></input><br />    
         </div>
         </p>
        <p>
         <div class="validateCC">    
        <label for="ccexpdate">CARD EXPIRY DATE:</label> <input type="text" name="txtExpDate" id="ccexpdate"></input>
         </div>
          <div class="validateCC">    
         <label for="ccexpdate" id="ccexpdate_error" class="validation-error">This field is required </label>      
         </div>   
        </p>
        <p>
         <div class="validateCC">    
        <label for="delStatus">CARD DELIVERY STATUS:</label> <select name="delStatus" id="delStatus">
            @foreach(var cDelStatus in ccDelStatus){
                if (cDelStatus.RefID.Equals("PEN")){
                    <option id="@cDelStatus.RefDesc" value=@cDelStatus.RefID selected="selected">@cDelStatus.RefDesc</option>}
                else{
                    <option id="@cDelStatus.RefDesc" value=@cDelStatus.RefID>@cDelStatus.RefDesc</option>}
            }            
        </select>
        </div>    
        </p>
        <p>
          <div class="validateCC">
             <label for="dremarks">DELIVERY REMARKS:</label> <textarea style="font-size:1.2em" name="dremarks" id="dremarks" cols="50" rows="10"></textarea>
        </div>  
        </p>    
        <p>
         <div class="validateCC">    
        <label for="delstatdate">DELIVERY STATUS DATE:</label> <input type="text" name="txtDelStatusDate" id="delstatdate"/>   
        </div>   
         <div class="validateCC">    
         <label for="delstatdate" id="delstatdate_error" class="validation-error">This field is required </label>      
         </div>   
        </p>
      
        <p>
         <div class="validateCC">    
         <label>CARD DELIVERY COURIER:</label>
          <select name="courier" id="courier">
            <option id="default_courier" value=""></option>
            @foreach(var cr in courierLkUp){
               <option id="@cr.Code"  value="@cr.Code">@cr.Name</option>  
            }
              
         </select>  
         </div>   
        </p>
        <p>
         <div class="validateCC">    
        <label>DELIVERY DATE:</label> <input type="text" name="DelDate" id="deldate"></input>
        </div>
         <div class="validateCC">    
        <label for="deldate" id="deldate_error" class="validation-error">This field is required </label>    
         </div>   
        </p>
         </fieldset>    
    <div id="cash_card_edit">
        
    </div>    
   
    </form>   
    </div>
    </div>
     <br/>
    <div id="grid">
    </div>
     
       
  
    